<?php

namespace Biz\service\advertisement\spotlight;

use Biz\cache\advertisement\CActivitySpotlight;
use Biz\cache\advertisement\CActivitySpotlightP2;
use Biz\cache\advertisement\CActivitySpotlightP3;
use Biz\cache\advertisement\CActivitySpotlightPN;
use Doraemon\pockets\constInterface\statSign\AutoPlatformModule;
use Doraemon\tools\IdParse;
use Doraemon\tools\ImgUrl;
use Doraemon\tools\LinkFormat;
use Hhzbeads\Img\ImageType;

class SpotlightConfig
{

    private $uid;
    private $brand_id;
    private $release_time;
    private $labels;
    private $tips;
    private $features;
    private $barrage;
    private $topic_id;
    private $winners;
    private $wiki_id;
    private $room_id;
    private $cache_handler;
    private $rank_config;
    private $statsign;
    private array $elements;
    private array $publishElements;


    /**
     * @param $uid
     * @param $brand_id
     * @param $release_time
     * @param $labels
     * @param $tips
     * @param $features
     * @param $barrage
     */
    public function __construct($uid, $brand_id, $release_time, $labels, $tips, $features, $barrage, $topic_id, $winners, $wiki_id, $room_id, $cache_handler = null, $rank_config = [], $statsign = [], $elements = [], $publishElements = [])
    {
        $this->uid = $uid;
        $this->brand_id = $brand_id;
        $this->release_time = $release_time;
        $this->labels = $labels;
        $this->tips = $tips;
        $this->features = $features;
        $this->barrage = $barrage;
        $this->topic_id = $topic_id;
        $this->winners = $winners;
        $this->wiki_id = $wiki_id;
        $this->room_id = $room_id;
        $this->cache_handler = $cache_handler;
        $this->rank_config = $rank_config;
        $this->statsign = $statsign;
        $this->elements = $elements;
        $this->publishElements = $publishElements;
    }

    const P_CONFIG = [
            'name' => '品牌聚光灯第4期',
            'brand_id' => '2877',
            'release_time' => '2022/11/9 0:00:00',
            'labels' => '自选变温：切换室温度自控，冷冻冷藏蔬果收纳按需切换
真空冰温：真空泵抽取空气，生鲜肉类原生态保鲜
美味速冻：内置铝盘快速冷冻，锁住食材水分及口感
自动制冰：无需外接水源，干净冰块极速制作
润泽低温冷藏：低温+润泽冷气保鲜，不包保鲜膜照样鲜美',
            'guess' => '真空冰温科技
498升大容量
IF设计大奖
三层强效除味
美味速冻
润泽低温冷藏
VIP真空隔热材料
自选变温
自动清洁制冰',
            'guess_rank' => '真空冰温科技
498升大容量
IF设计大奖
三层强效除味
美味速冻',
            'share_title' => '好好住|新品聚光灯04期',
            'share_msg' => '当一切可以自由选择，生活才会倍加鲜活，猜猜新朋友是谁~',
            'share_img' => 'f7fee308c08c0vJ00rknkqa',
            'bg_color' => 'F3EBDE',
            'brand_bg_img' => '6882730hy03k0w200rknrfv',
            'guess_color' => 'D3B892,D3B892',
            'guess_selected_color' => 'CAA05F,B18954',
            'guess_result_color' => 'FFFFFF,FFFFFF,C6B69B',
            'guess_prepare_statsign' => 'products_spotlight_order_v4',
            'main_pic' => '3543f30ku0va0vV00rklwll',
            'box_pic' => 'b0f6330hu0qm0Jm00rklwlt,7e71030hu0n60tH00rklwly,9c5a530hu0n60LK00rklwmc,b9f2530cw0as0ak00rklwmg,8116a30hu0n606M00rklwnl,e009630ck02m0cV00rklwo2',
            'guess_pic' => '0eb61306y0160SO00rklwvf,5e61930bq00s0D900rkno4u,da60e300y00s0rQ00rklwp7,e915c30i002m0kX00rklwpk,e13c830i002m07500rklwps,3d5dd30ew00s0Xp00rklwqe',
            'prepare_other_pic' => 'b185c30hu08q0nI00rklwc1,0f2a930ku0540nF00rklwc7',
        'wiki_title' => '海尔叠黛和美洗干集成机H9Y12BLD12U1',
        'wiki_price' => '¥19999',
        'wiki_id' => '269906',
        'wiki_link' => 'https://3.cn/108-ik14f',
        'barrage' => '低噪音运行，夜间洗衣也不扰民
高度降低到了167cm，不用垫脚也能操作
玉黛青色高级大气，颜控者爱了爱了～
无需再次熨烫，衣物烘出来不打结无褶皱
167cm操作高度，平视操作nice！
同向开门设计，取放衣物不打架
三重健康除菌,小朋友也能安心穿衣
四重线屑过滤带走猫毛，养猫人实现黑衣自由
20分钟衣物快速烘干，Hybird速热科技yyds!
洗烘接力，提前15分种预热烘得快
无需等待，远程手机也能操作
洗干护三合一，一套变一体
隔夜衣直接空气洗，无需水洗秒变净衣
一屏智控，所有洗干护动作都能操作
一体式外观，嵌在哪里都好看！
无需操心，放多少洗衣液TA来定
专洗专烘专护，各种面料都能搞定
不用二次晾晒，大件床品即烘即用
无水盒设计，使用更便捷
多件烘得快，大件烘得透',
        'publish_barrage_color' => 'FCFAF6',
        'publish_barrage_pic' => '9c218301a01c0Ta00rkpja9,69926301a01c0SH00rkpjat',
        'video' => 'http://video-play-hb2.haohaozhu.cn/821ac39602e8405f89dfe61875f2b370/7caf662db24e4871be79f2e19477b8ee-448f2c8516c3fd26bbcfb478c1ab581c-sd.mp4',
        'publish_video_pic' => '69c0730hu0160J500rkpjse,f12e030i00a604C00rkpjtc',
        'room_id' => '841',
        'publish_room_pic' => '6cb4430i006i00R00rkpjqk',
        'topic_id' => '1617',
        'features' => '洗干护一体
一屏控制
洗烘同向开门
洗烘联动
直驱电机
双擎热泵烘干
负离子空气洗
1.67cm高度更低
一体式外观',
        'features_bg_color' => 'F0E2CC,F0E2CC',
        'features_unselected_color' => 'D3B892,D3B892',
        'features_selected_color' => 'CAA05F,B18954',
        'winners' => '住友cccss,xiaowu,sansan',
        'publish_share_title' => '好好住|新品聚光灯04期',
        'publish_share_msg' => '当一切可以自由选择，生活才会倍加鲜活，海尔喜干集成机',
        'publish_bg_pic' => '960a330kw1pq0NN00rkpkuc',
        'publish_share_img' => 'f7fee308c08c0vJ00rknkqa',
        'publish_bg_color' => 'F3EBDE',
        'publish_statsign' => 'products_spotlight_v4',
        'publish_product_pic' => '9911030bo0h80nC00rkpkt9,b8e6730hy04u0Y700rkptx5',
        'publish_buy_pic' => '75c20307g0160z100rkpkwt,0c7a630i006i09a00rkprng',
        'publish_note_pic' => '0a28a306y0160aH00rkprm4,26e7c30ku0qs0Ji00rkplj6,650c230ku0qs0kX00rkpljw,9937230ku0r60VK00rkplk9,2d1f430ku0r60W000rkplkp',
        'publish_box_pic' => '3c9da30hu0oq0WW00rkplmd,c4b2c30hu0oq0Ht00rkplnh,9548b30cw0as0oo00rkplqu,e580730hu0oq0IX00rkplny,9e86f30ck02m0Wu00rkploo',
        'publish_main_pic' => '9a4e030ku0va0Jo00rkprh8',
        'publish_brand_bg_pic' => '39cb630hy03k00l00rkpvor',
        'publish_features_pic' => '3ec89307u0160ws00rkprom,3a52a309200q0hL00rkprpp,3d2cb30ku01g0D700rkprq8,8c25830ku01g0IG00rkprqj,260fc300y00s0Yl00rkprqv',
        'publish_award_pic' => '7f91b30bo0160bw00rkpstg,2e3a830ks0260VU00rkpsu0,1167430h003u0pX00rkpsum,1e09530gs02o03M00rkpsvm,31bc930gs02m06U00rkpsw1',
        'publish_pool_img' => 'f46a630fi0160nj00rkpsys',
        'publish_button_img' => '690f530j003m05F00rkpsze',
        'publish_note' => '00607c3000017gw4,0060685000001d7o,00605ue000001yet,006065q00000vnzr',
    ];
    public static function p($p, $uid)
    {
        $handler = new CActivitySpotlightPN();
        $handler::setP($p);
        $config = CActivitySpotlightPN::getConfig(self::getId($p));
        $config = json_decode($config, true);
//        $config = self::P_CONFIG;
        $brand_id = $config['brand_id'] ?? 0;
        $release_time = strtotime($config['release_time'] ?? '');
        $labels = self::explodeWithTrim($config['guess'], "\n", true);
        $tips = self::explodeWithTrim($config['labels']);
        $rank = self::explodeWithTrim($config['guess_rank']);
        $features = self::explodeWithTrim($config['features'], "\n", true);
        $barrage = self::explodeWithTrim($config['barrage']);
        $topic_id = $config['topic_id'] ?? 0;
        $winners = self::explodeWithTrim($config['winners'] ?? '', ',');
        $wiki_id = $config['wiki_id'] ?? 0;
        $room_id = $config['room_id'] ?? 0;
        $rank_config = [
            'necessary' => $rank,
            'allow' => [],
            'limit' => count($rank),
            'allowed' => false,
        ];
        $statsign = [
            'note' => $config['publish_note_statsign'] ?? '',
            'wiki' => $config['publish_wiki_statsign'] ?? '',
        ];
        $elements = [
            'name' => $config['name'],
            'share_title' => $config['share_title'],
            'share_msg' => $config['share_msg'],
            'share_img' => self::images($config['share_img']),
            'bg_color' => $config['bg_color'],
            'brand_bg_img' => self::images($config['brand_bg_img']),
            'brand_name_color' => $config['brand_name_color'],
            'brand_unfav_color' => $config['brand_unfav_color'],
            'brand_fav_color' => $config['brand_fav_color'],
            'guess_color' => $config['guess_color'],
            'guess_selected_color' => $config['guess_selected_color'],
            'guess_result_color' => $config['guess_result_color'],
            'guess_prepare_statsign' => $config['guess_prepare_statsign'],
            'main_pic' => self::images($config['main_pic']),
            'box_pic' => self::images($config['box_pic']),
            'guess_pic' => self::images($config['guess_pic']),
            'prepare_other_pic' => self::images($config['prepare_other_pic']),
        ];
        $publishElements = [
            'name' => $config['name'],
            'share_title' => $config['publish_share_title'],
            'share_msg' => $config['publish_share_msg'],
            'share_img' => self::images($config['publish_share_img']),
            'bg_pic' => self::images($config['publish_bg_pic']),
            'bg_color' => $config['publish_bg_color'],
            'publish_main_pic' => self::images($config['publish_main_pic']),
            'brand_bg_pic' => self::images($config['publish_brand_bg_pic']),
            'box_pic' => self::images($config['publish_box_pic']),
            'product_pic' => self::images($config['publish_product_pic']),
            'publish_brand_name_color' => $config['publish_brand_name_color'],
            'publish_brand_unfav_color' => $config['publish_brand_unfav_color'],
            'publish_brand_fav_color' => $config['publish_brand_fav_color'],
            'wiki_title' => $config['wiki_title'],
            'wiki_price' => $config['wiki_price'],
            'wiki_id' => $config['wiki_id'],
            'barrage_pic' => self::images($config['publish_barrage_pic']),
            'barrage_color' => $config['publish_barrage_color'],
            'video_pic' => self::images($config['publish_video_pic']),
            'video' => $config['video'],
            'note_pic' => self::images($config['publish_note_pic']),
            'publish_note' => self::link($config['publish_note']),
            'publish_buy_pic' => self::images($config['publish_buy_pic']),
            'wiki_link' => $config['wiki_link'],
            'room_pic' => self::images($config['publish_room_pic']),
            'features_pic' => self::images($config['publish_features_pic']),
            'features_bg_color' => $config['features_bg_color'],
            'features_unselected_color' => $config['features_unselected_color'],
            'features_selected_color' => $config['features_selected_color'],
            'award_pic' => self::images($config['publish_award_pic']),
            'pool_img' => self::images($config['publish_pool_img']),
            'button_img' => self::images($config['publish_button_img']),
            'publish_statsign' => $config['publish_statsign'],
        ];
        return new self($uid, $brand_id, $release_time, $labels, $tips, $features, $barrage, $topic_id, $winners, $wiki_id, $room_id, new CActivitySpotlightPN(), $rank_config, $statsign, $elements, $publishElements);
    }

    public static function getId($id): string
    {
        return md5($id . 'Spotlight');
    }

    public static function explodeWithTrim($str, $separator = "\n", $iota = false): array
    {
        $response = [];
        $temp = explode($separator, $str);
        foreach ($temp as $k => $v) {
            $v = trim($v);
            if ($v) {
                if ($iota) {
                    $response[1 << $k] = $v;
                } else {
                    $response[] = $v;
                }
            }
        }
        return $response;
    }

    public static function link($id)
    {
        $ids = is_array($id) ? $id : explode(',', $id);
        $response = [];
        foreach ($ids as $v) {
            $response[] = [
                'obj_type' => IdParse::getType($v),
                'obj_id' => $v,
            ];
        }
        return is_array($id) || (count($ids) > 1) ? $response : current($response);
    }

    public static function images($pic)
    {
        $pics = is_array($pic) ? $pic : explode(',', $pic);
        $response = [];
        foreach ($pics as $v) {
            $response[] = ImgUrl::getUrl(ImageType::APPTYPE_OP, $v, ImageType::IMAGE_SIZE_OP_ORI);
        }
        return is_array($pic) || (count($pics) > 1) ? $response : current($response);
    }

    public static function p1($uid = 0): SpotlightConfig
    {
        $labels = [
            1 => '双子舱',
            2 => '超大上筒',
            4 => 'UVC紫外线除菌',
            8 => '负氧离子护理',
            16 => '海量藏鲜',
            32 => '操作智能',
            64 => '新风系统',
            128 => '离子柔烘',
            256 => '减震平衡',
            512 => '99.99%除菌率',
            1024 => '大功率立体声'
        ];
        $tips = [
            '分区洗好用：10+6KG双子舱分区洗，满足全家人需求',
            '大上筒好用：6公斤超大上筒，洗得更多，洗的更干净',
            '离子风好用：离子柔护+离子空气洗，衣物烘得更蓬松',
            '智能投放好用：AI双向智能投放，洗得干净无泡沫',
            '除菌好用：UVC紫外线除菌，除菌率99.99%，除螨率100%',
        ];
        $features = [
            512 => "APP远程操控",
            2 => "离子柔烘",
            4 => "UVC紫外线除菌",
            8 => "离子空气洗",
            16 => "AI双向智能投放",
            32 => "双直驱变频电机",
            64 => "嵌入式设计",
            128 => "1.3m操作高度",
            256 => "炫彩大屏",
            1 => "10+6kg双子舱分区洗",
        ];
        $barrage = [
            '10+6kg双子舱分区洗，衣物分区洗护更健康',
            '16KG大容量，全家衣服一次洗！',
            '内外衣物分区洗，真解放双手',
            '和串色say NO，深浅衣物分区洗',
            '大人小孩衣服分开洗，给宝贝更细致呵护',
            '上筒放取不卡衣，510mm大筒径，360mm大取衣口yyds!',
            'UVC紫外线除菌，除菌率99.99%,敏感肌肤安心穿',
            '离子柔烘黑科技，衣物蓬松有型免熨烫',
            '隔夜衣就交给离子空气洗吧！无水洗涤快速祛味！',
            '摆脱手动添加洗衣液困难症，AI双向智能投放放多放少它来定！',
            '嵌入式安装超省空间',
            '1.3m操作高度，提升操作舒适感',
            '洗衣不吵，运行噪音低至45dB，夜洗也安静～',
            '双直趋变频电机，动力强劲洗衣稳定',
            '门中超大炫彩屏，触控操作超便捷',
            '手机APP远程操控，不在家也能洗衣',
            '满足精细化洗衣需求，多个洗涤程序按需选',
            '不想水洗就用离子空气洗，蓬松祛味除菌三效合一',
            'AI双舱智能投放，一次添加用一个月',
            '超柔羊毛洗，羊绒大衣放心洗！',
        ];
        $release_time = strtotime('2022-09-20 20:00:00');
        $brand_id = 483;
        $topic_id = 1617;//1617
        $winners = ["煢貓","小五六七30","忙叨小杨子"];//["住友***","张晓敏","桃桃cola"];
        $wiki_id = 263533;//263533 264257
        $room_id = 836;
        return new self($uid, $brand_id, $release_time, $labels, $tips, $features, $barrage, $topic_id, $winners, $wiki_id, $room_id, new CActivitySpotlight);
    }

    public static function p2($uid = 0): SpotlightConfig
    {
        $labels = [
            1 => '独立三系统',
            2 => '分子级保鲜',
            4 => '双向恒温送风',
            8 => '除菌率99.999%',
            16 => '青墨岩岩板面板',
            32 => '一级能效',
            64 => 'Wi-Fi智能互联',
            128 => '烟灶联动',
            256 => '即热即饮',
            512 => '智能人感科技',
            1024 => '超薄不跑烟',
            2048 => '蒸烤炸一体',
        ];
        $tips = [
            '巨能装：555L大容量，果肉鲜蔬放心囤',
            '随需定：独立三系统，冷藏冷冻自由变',
            '特保鲜：分子保鲜科技，新鲜美味留得住',
            '真灭菌：GP+光电超净技术，除菌率99.999%',
            '快除味：10分急速净味，食材新鲜不串味',
        ];
        $features = [
            1 => "独立三系统",
            2 => "分子级保鲜",
            4 => "GP+光电超净技术",
            8 => "智能人感科技",
            16 => "10分钟急速净味技术",
            32 => "555升大容量",
            64 => "青墨岩岩板面板",
            128 => "双变温空间",
            256 => "风冷无霜技术",
        ];
        $barrage = [
            '四区双变温，冷冻冷藏我来定',
            '分子保鲜科技，把每一味新鲜留住',
            '-18ºC~5ºC自由变温，为不同食材精准养鲜',
            '三系统独立制冷，冷冻冷藏随食变',
            '大自由储鲜抽屉，自由拿取自由摆放',
            '分区储鲜，果蔬不沾荤腥味',
            '555L黄金大容量，装得下一家人的口味',
            'GP+光电超净技术，守护家人的饮食健康',
            '十分钟急速净味，净化冰箱内部空气',
            '青墨岩艺术岩版，完美提升家居格调',
            '智能人感科技，靠近冰箱自动点亮',
            '美妆药材母婴果蔬，不同品类同样保鲜',
            '长效锁鲜，珍贵食材营养留得住',
            '除菌率99.999%，源头除菌入口更安心',
            '6D长效锁鲜，守护食材原鲜滋味',
            '养鲜时空不受限，放得下四季新鲜',
            '密封保鲜盒，独立分储特殊食材',
            '净味快人一步，冰箱时刻清新如初',
            '食材分子静止休眠，保鲜效果一级棒',
            '容量大出新花样，时令美味尽情囤',
        ];
        $rank_config = [
            'necessary' => ['独立三系统','分子级保鲜','除菌率99.999%', '一级能效', 'Wi-Fi智能互联', '智能人感科技'],
            'allow' => [],
            'limit' => 5,
            'allowed' => false,
        ];
        $release_time = strtotime('2022-10-10 20:00:00');
        $brand_id = 483;
        $topic_id = 1617;//1617
        $winners = ["小_小蓉吖","四个不佛","凌风哟"];
        $wiki_id = 267912;
        $room_id = 841;
        $statsign = [
            'note' => AutoPlatformModule::MODULE_PRODUCTS_SPOTLIGHT_VTWO_NOTE,
            'wiki' => AutoPlatformModule::MODULE_PRODUCTS_SPOTLIGHT_VTWO_WIKI_CARD,
        ];
        return new self($uid, $brand_id, $release_time, $labels, $tips, $features, $barrage, $topic_id, $winners, $wiki_id, $room_id, new CActivitySpotlightP2, $rank_config, $statsign);
    }

    public static function p3($uid = 0): SpotlightConfig
    {
        $labels = [
            1 => '真空冰温科技',
            2 => '498升大容量',
            4 => 'IF设计大奖',
            8 => '三层强效除味',
            16 => '美味速冻',
            32 => '润泽低温冷藏',
            64 => 'VIP真空隔热材料',
            128 => '自选变温',
            256 => '自动清洁制冰',
        ];
        $tips = [
            '自选变温：切换室温度自控，冷冻冷藏蔬果收纳按需切换',
            '真空冰温：真空泵抽取空气，生鲜肉类原生态保鲜',
            '美味速冻：内置铝盘快速冷冻，锁住食材水分及口感',
            '自动制冰：无需外接水源，干净冰块极速制作',
            '润泽低温冷藏：低温+润泽冷气保鲜，不包保鲜膜照样鲜美',
        ];
        $features = [
            1 => "真空冰温技术",
            2 => "自选变温",
            4 => "美味速冻",
            8 => "润泽低温冷藏",
            16 => "自动清洁制冰",
            32 => "498升大容量",
        ];
        $barrage = [
            '长效保鲜的秘诀是减少空气含量，真空才能真保鲜！',
            '冷藏冷冻蔬果收纳随需切换，打造你的专属冰箱！',
            '真空冰温下快速渗透，腌渍美食少等待',
            '拥有6门的变温冰箱，才是我的菜！',
            '直接给水式自动制冰yyds！饮料加冰的快乐又回来了！',
            '美味速冻，内置铝盘可快速冷冻食材！',
            '自由定义冰箱分区，自定义自己的生活方式！',
            '真空冰温技术真的可！拿出来还跟刚买一样新鲜！',
            'VIP真空隔热材料，隔热性能强大',
            '为吃货而生！囤珍贵食材也无需担心！',
            '真空冰温，带来休眠级保鲜',
            '567升大容量，囤货再多也能装得下！',
            '日本生产制造，整机原装进口',
            '肉类鱼类持续保鲜，一周后食用不影响口感',
            '强大锁鲜能力，带来健康又有营养的的品质生活',
            '润泽低温冷藏=低温+润泽冷气保鲜，满足储鲜想象',
            '切换室自由变温，冷冻冷藏蔬果收纳随心变',
            '高颜值外表，放在哪里都适配',
            '润泽低温冷藏，带来极致保鲜力',
            '不用外接水源，直接加水就能快速制冰',
        ];
        $rank_config = [
            'necessary' => ['真空冰温科技','498升大容量','三层强效除味', '美味速冻', '润泽低温冷藏', 'VIP真空隔热材料', '自选变温', '自动清洁制冰'],
            'allow' => [],
            'limit' => 5,
            'allowed' => false,
        ];
        $release_time = strtotime('2022-10-24 00:00:00');
        $brand_id = 2877;
        $topic_id = 0;
        $winners = ["Free7dom","SOOOOOOONG","青儿妹妹"];
        $wiki_id = 269906;
        $room_id = 0;
        $statsign = [
            'note' => AutoPlatformModule::MODULE_PRODUCTS_SPOTLIGHT_VTWO_NOTE,
            'wiki' => AutoPlatformModule::MODULE_PRODUCTS_SPOTLIGHT_V3_WIKI_CARD,
        ];
        return new self($uid, $brand_id, $release_time, $labels, $tips, $features, $barrage, $topic_id, $winners, $wiki_id, $room_id, new CActivitySpotlightP3, $rank_config, $statsign);
    }

    public function getReleaseTime()
    {
        return $this->release_time;
    }

    public function getLabels()
    {
        return $this->labels;
    }

    public function getTips()
    {
        return $this->tips;
    }

    public function getUid()
    {
        return $this->uid;
    }

    public function getBrandId()
    {
        return $this->brand_id;
    }

    public function getFeatures()
    {
        return $this->features;
    }

    public function getBarrage()
    {
        return $this->barrage;
    }

    public function getWinners()
    {
        return $this->winners;
    }

    public function getTopicId()
    {
        return $this->topic_id;
    }

    public function getWikiId()
    {
        return $this->wiki_id;
    }

    public function getRoomId()
    {
        return $this->room_id;
    }

    public function getCacheHandler()
    {
        return $this->cache_handler;
    }

    public function getRankConfig(): array
    {
        return $this->rank_config;
    }

    public function getStatsign(): array
    {
        return $this->statsign;
    }

    public function getElements(): array
    {
        return $this->elements;
    }

    public function getPublishElements(): array
    {
        return $this->publishElements;
    }
}